******************************************
**	title:	left-right-gender-ejpr.do 	**
**	author:	ruth dassonneville 			**
** 	date:	january 2020 				**
**	data:	left-right-gender.dta 		**
******************************************

/* Note: This do-file replicates the main and supplementary analyses from the paper 'Change and Continuity in the ideological gender gap. A longitudinal analysis of left-right self-placement in OECD countries' by Ruth Dassonneville. The paper appears in the European Journal of Political Research. */


** set working directory and load data (change if needed)

	cd "~/Dropbox/leftright women/paper/replication materials"
	use "left-right-gender.dta", clear

** generate variables that identify 'old' countries in the dataset

	sort country
	by country: sum year if ideology_st!=.

	gen since1970=.
	replace since1970=1 if iso=="BEL"
	replace since1970=1 if iso=="DNK"
	replace since1970=1 if iso=="FRA"
	replace since1970=1 if iso=="DEU"
	replace since1970=1 if iso=="IRL"
	replace since1970=1 if iso=="ITA"
	replace since1970=1 if iso=="LUX"
	replace since1970=1 if iso=="NLD"
	replace since1970=1 if iso=="GBR"

	gen since1985=.
	replace since1985=since1970
	replace since1985=1 if iso=="CAN"
	replace since1985=1 if iso=="GRC"
	replace since1985=1 if iso=="ISR"
	replace since1985=1 if iso=="JPN"
	replace since1985=1 if iso=="PRT"
	replace since1985=1 if iso=="KOR"
	replace since1985=1 if iso=="ESP"
	replace since1985=1 if iso=="USA"

** create additional time variables	

	gen generation=1 if year_of_birth>=1910 & year_of_birth<=1924
	replace generation=2 if year_of_birth>1924 & year_of_birth<=1944
	replace generation=3 if year_of_birth>1944 & year_of_birth<=1964
	replace generation=4 if year_of_birth>1964 & year_of_birth<=1980
	replace generation=5 if year_of_birth>1980 & year_of_birth<=1996
	replace generation=6 if year_of_birth>1996 & year_of_birth<=2010
	
	label define generation 1 "Greatest" 2 "Silent" 3 "Boomers" 4 "Gen-X" 5 "Gen-Y" 6 "Gen-Z"
	label values generation generation
	
	egen birthcohort = cut(year_of_birth), at(1910 1915 1920 1925 1930 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 	1985 1990 1995 2000  2005)
	replace birthcohort=. if year_of_birth<1910
	
	gen year2=year*year
	gen age2=age*age
	
	egen decade = cut(year), at(1970 1980 1990 2000 2010 2020)	


	
******************
** main results **	
******************


** non-parametric estimation, focus on countries that are included since 1973
	
	twoway lpolyci ideology_st year if gender==0 & since1970==1 || lpolyci ideology_st year if gender==1 & ///
	since1970==1, saving(trends1970.gph, replace) xtitle("Year") ytitle("Left-right self-placement") ///
	note("Ideological position of women (solid line) and men (dashed line).")

	* estimates from smoother line
	lpoly ideology_st year if gender==1 & since1970==1, generate(at1 smooth1) se(se1) nograph	
	lpoly ideology_st year if gender==0 & since1970==1, generate(at2 smooth2) se(se2) nograph	
	
** time trends by country
	twoway lpolyci ideology_st year if gender==0 & iso=="AUS" || lpolyci ideology_st year if gender==1 & iso=="AUS", saving(trends_AUS.gph, replace) title("Australia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="AUT" || lpolyci ideology_st year if gender==1 & iso=="AUT", saving(trends_AUT.gph, replace) title("Austria") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="BEL" || lpolyci ideology_st year if gender==1 & iso=="BEL", saving(trends_BEL.gph, replace) title("Belgium") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid) 
	twoway lpolyci ideology_st year if gender==0 & iso=="CAN" || lpolyci ideology_st year if gender==1 & iso=="CAN", saving(trends_CAN.gph, replace) title("Canada") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="CHL" || lpolyci ideology_st year if gender==1 & iso=="CHL", saving(trends_CHL.gph, replace) title("Chile") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="CZE" || lpolyci ideology_st year if gender==1 & iso=="CZE", saving(trends_CZE.gph, replace) title("Czechia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="DNK" || lpolyci ideology_st year if gender==1 & iso=="DNK", saving(trends_DNK.gph, replace) title("Denmark") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="EST" || lpolyci ideology_st year if gender==1 & iso=="EST", saving(trends_EST.gph, replace) title("Estonia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="FIN" || lpolyci ideology_st year if gender==1 & iso=="FIN", saving(trends_FIN.gph, replace) title("Finland") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="FRA" || lpolyci ideology_st year if gender==1 & iso=="FRA", saving(trends_FRA.gph, replace) title("France") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="DEU" || lpolyci ideology_st year if gender==1 & iso=="DEU", saving(trends_DEU.gph, replace) title("Germany") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="GRC" || lpolyci ideology_st year if gender==1 & iso=="GRC", saving(trends_GRC.gph, replace) title("Greece") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="HUN" || lpolyci ideology_st year if gender==1 & iso=="HUN", saving(trends_HUN.gph, replace) title("Hungary") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="ISL" || lpolyci ideology_st year if gender==1 & iso=="ISL", saving(trends_ISL.gph, replace) title("Iceland") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="IRL" || lpolyci ideology_st year if gender==1 & iso=="IRL", saving(trends_IRL.gph, replace) title("Ireland") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="ISR" || lpolyci ideology_st year if gender==1 & iso=="ISR", saving(trends_ISR.gph, replace) title("Israel") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="ITA" || lpolyci ideology_st year if gender==1 & iso=="ITA", saving(trends_ITA.gph, replace) title("Italy") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="JPN" || lpolyci ideology_st year if gender==1 & iso=="JPN", saving(trends_JPN.gph, replace) title("Japan") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="LVA" || lpolyci ideology_st year if gender==1 & iso=="LVA", saving(trends_LVA.gph, replace) title("Latvia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="LTU" || lpolyci ideology_st year if gender==1 & iso=="LTU", saving(trends_LTU.gph, replace) title("Lithuania") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="LUX" || lpolyci ideology_st year if gender==1 & iso=="LUX", saving(trends_LUX.gph, replace) title("Luxembourg") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="MEX" || lpolyci ideology_st year if gender==1 & iso=="MEX", saving(trends_MEX.gph, replace) title("Mexico") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="NLD" || lpolyci ideology_st year if gender==1 & iso=="NLD", saving(trends_NLD.gph, replace) title("Netherlands") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="NZL" || lpolyci ideology_st year if gender==1 & iso=="NZL", saving(trends_NZL.gph, replace) title("New Zealand") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="NOR" || lpolyci ideology_st year if gender==1 & iso=="NOR", saving(trends_NOR.gph, replace) title("Norway") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="POL" || lpolyci ideology_st year if gender==1 & iso=="POL", saving(trends_POL.gph, replace) title("Poland") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="PRT" || lpolyci ideology_st year if gender==1 & iso=="PRT", saving(trends_PRT.gph, replace) title("Portugal") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="SVK" || lpolyci ideology_st year if gender==1 & iso=="SVK", saving(trends_SVK.gph, replace) title("Slovakia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="SVN" || lpolyci ideology_st year if gender==1 & iso=="SVN", saving(trends_SVN.gph, replace) title("Slovenia") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="KOR" || lpolyci ideology_st year if gender==1 & iso=="KOR", saving(trends_KOR.gph, replace) title("South Korea") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="ESP" || lpolyci ideology_st year if gender==1 & iso=="ESP", saving(trends_ESP.gph, replace) title("Spain") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="SWE" || lpolyci ideology_st year if gender==1 & iso=="SWE", saving(trends_SWE.gph, replace) title("Sweden") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="CHE" || lpolyci ideology_st year if gender==1 & iso=="CHE", saving(trends_CHE.gph, replace) title("Switzerland") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="TUR" || lpolyci ideology_st year if gender==1 & iso=="TUR", saving(trends_TUR.gph, replace) title("Turkey") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="GBR" || lpolyci ideology_st year if gender==1 & iso=="GBR", saving(trends_GBR.gph, replace) title("United Kingdom") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)
	twoway lpolyci ideology_st year if gender==0 & iso=="USA" || lpolyci ideology_st year if gender==1 & iso=="USA", saving(trends_USA.gph, replace) title("United States of America") xtitle("Year") ytitle("Left-right self-placement") xlabel(,nogrid) ylabel(,nogrid)	

** parametric estimation of change over time
	
	gen isoyear=iso+string(year)
	encode isoyear, gen(isoyear_num)

	** decade FEs 
	eststo m1: reg ideology_st i.gender i.decade  i.isocode if since1970==1, cluster(isoyear_num)
	eststo m2: reg ideology_st i.gender##i.decade   i.isocode if since1970==1, cluster(isoyear_num)
	eststo m3: reg ideology_st i.gender i.decade  i.isocode if since1985==1, cluster(isoyear_num)
	eststo m4: reg ideology_st i.gender##i.decade   i.isocode if since1985==1, cluster(isoyear_num)
	eststo m5: reg ideology_st i.gender i.decade  i.isocode , cluster(isoyear_num)
	eststo m6: reg ideology_st i.gender##i.decade   i.isocode , cluster(isoyear_num)
	
	esttab m1 m2 m3 m4 m5 m6 using table_decades.rtf, b(3) se(3) r2 nogap replace
	
	** change over time, generational replacement	
	eststo m1: reg ideology_st i.gender i.generation age age2 i.decade  i.isocode if since1970==1, cluster(isoyear_num)
	eststo m2: reg ideology_st i.gender##i.generation age age2 i.decade i.isocode if since1970==1, cluster(isoyear_num)
	
	margins gender, at(generation=(1 2 3 4 5 6)) vsquish
	marginsplot, saving(amegeneration70.gph, replace)



****************************
** supplementary materials **	
*****************************

	** N observations by country and by dataset (Appendix A)
	
	gen maxdata=1 if ideology_st!=. & gender!=.

	sort iso year
	by iso: sum year if maxdata==1
	
	tab iso dataset_category if maxdata==1


	** 	country-specific analaysis of effect of 'female' over time (focus on AME by decade) (Appendix B)
	
	reg ideology_st i.gender##i.decade if iso=="AUS"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="AUT"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="BEL"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="CAN"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="CHE"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="CHL"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="CZE"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="DEU"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="DNK"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="ESP"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="EST"
	margins , dydx(gender) at(decade=(2000 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="FIN"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="FRA"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="GBR"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="GRC"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="HUN"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="IRL"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="ISL"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="ISR"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="ITA"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="JPN"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="KOR"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="LTU"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="LUX"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="LVA"
	margins , dydx(gender) at(decade=(2000 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="MEX"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="NLD"
	margins , dydx(gender) at(decade=(1970 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="NOR"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="NZL"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="POL"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="PRT"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="SVK"
	margins , dydx(gender) at(decade=(2000 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="SVN"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="SWE"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="TUR"
	margins , dydx(gender) at(decade=(1990 (10) 2010)) 
	reg ideology_st i.gender##i.decade if iso=="USA"
	margins , dydx(gender) at(decade=(1980 (10) 2010)) 
	
	
	** generational models, and plots for since 1985 and all data (Appendix C)
	
	eststo m1: reg ideology_st i.gender i.generation age age2 i.decade  i.isocode if since1970==1, cluster(isoyear_num)
	eststo m2: reg ideology_st i.gender##i.generation age age2 i.decade i.isocode if since1970==1, cluster(isoyear_num)
	
	eststo m3: reg ideology_st i.gender i.generation age age2 i.decade i.isocode if since1985==1, cluster(isoyear_num)
	eststo m4: reg ideology_st i.gender##i.generation age age2 i.decade i.isocode if since1985==1, cluster(isoyear_num)
	
	margins gender, at(generation=(1 2 3 4 5 6)) vsquish
	marginsplot, saving(amegeneration85.gph, replace)
	
	eststo m5: reg ideology_st i.gender i.generation age age2 i.decade i.isocode , cluster(isoyear_num)
	eststo m6: reg ideology_st i.gender##i.generation  age age2 i.decade i.isocode , cluster(isoyear_num)
	
	margins gender, at(generation=(1 2 3 4 5 6)) vsquish
	marginsplot, saving(amegeneration.gph, replace)

	esttab m1 m2 m3 m4 m5 m6 using table_generations.rtf, b(3) se(3) r2 nogap replace

	
	** apc model with focus on birth cohorts (Appendix D)
		
	eststo m1: reg ideology_st i.gender##i.birthcohort age age2 i.decade   i.isocode if since1970==1 , cluster(isoyear_num)
	margins gender, at(birthcohort=(1915 (5) 1995)) vsquish
	marginsplot, saving(gapcohorts70.gph, replace)
	
	eststo m2: reg ideology_st i.gender##i.birthcohort age age2 i.decade   i.isocode if since1985==1 , cluster(isoyear_num)
	margins gender, at(birthcohort=(1915 (5) 1995)) vsquish
	marginsplot, saving(gapcohorts85.gph, replace)
	
	eststo m3: reg ideology_st i.gender##i.birthcohort age age2 i.decade   i.isocode  , cluster(isoyear_num)
	margins gender, at(birthcohort=(1915 (5) 1995)) vsquish
	marginsplot, saving(gapcohorts.gph, replace)
	
	esttab m1 m2 m3 using table_cohorts.rtf, b(3) se(3) r2 nogap replace
	
	
	** taking into account autocorrelation (Appendix E)
	
		* approach 1: year-by-year analysis and plotting coefficients
	
			* countries since 1970
			set more off
			tempname yearanalyses70
	
			postfile `yearanalyses70' year  b_gender se_gender using yearanalyses70.dta , replace

			foreach i of num  1973 1976/2017  {
			reg ideology_st gender  i.isocode if year==`i' & since1970==1  , cluster(isoyear_num)
			post `yearanalyses70' (`i') (`=_b[gender]') (`=_se[gender]') 
			}
			postclose `yearanalyses70' 
	
			* countries since 1985
			set more off
			tempname yearanalyses85
	
			postfile `yearanalyses85' year  b_gender se_gender using yearanalyses85.dta , replace

			foreach i of num  1973 1976/2017  {
			reg ideology_st gender  i.isocode if year==`i' & since1985==1  , cluster(isoyear_num)
			post `yearanalyses85' (`i') (`=_b[gender]') (`=_se[gender]') 
			}
			postclose `yearanalyses85' 

			* full dataset
			set more off
			tempname yearanalyses
	
			postfile `yearanalyses' year  b_gender se_gender using yearanalyses.dta , replace

			foreach i of num  1973 1976/2017  {
			reg ideology_st gender  i.isocode if year==`i'   , cluster(isoyear_num)
			post `yearanalyses' (`i') (`=_b[gender]') (`=_se[gender]') 
			}
			postclose `yearanalyses' 
		
		
			* plot results	
			use yearanalyses70.dta, clear
			serrbar b_gender se_gender year , saving(yearcoefficients70.gph, replace) ///
			ytitle("Coefficient for female (vs. male)") xtitle("") title("9 countries") yline(0)
	
			use yearanalyses85.dta, clear
			serrbar b_gender se_gender year , saving(yearcoefficients80.gph, replace) ///
			ytitle("Coefficient for female (vs. male)") xtitle("") title("17 countries") yline(0)
	
			use yearanalyses.dta, clear
			serrbar b_gender se_gender year , saving(yearcoefficientsfull.gph, replace) ///
			ytitle("Coefficient for female (vs. male)") xtitle("") title("36 countries") yline(0)

			graph combine 	yearcoefficients70.gph yearcoefficients80.gph yearcoefficientsfull.gph, col(1) xsize(4) ysize(8)
	
		* approach 2:  transform to deviation and model deviation from mean - over time
		
		cd "~/Dropbox/leftright women/paper/replication materials"
		use "left-right-gender.dta", clear
		
		gen since1970=.
		replace since1970=1 if iso=="BEL"
		replace since1970=1 if iso=="DNK"
		replace since1970=1 if iso=="FRA"
		replace since1970=1 if iso=="DEU"
		replace since1970=1 if iso=="IRL"
		replace since1970=1 if iso=="ITA"
		replace since1970=1 if iso=="LUX"
		replace since1970=1 if iso=="NLD"
		replace since1970=1 if iso=="GBR"

		gen since1985=.
		replace since1985=since1970
		replace since1985=1 if iso=="CAN"
		replace since1985=1 if iso=="GRC"
		replace since1985=1 if iso=="ISR"
		replace since1985=1 if iso=="JPN"
		replace since1985=1 if iso=="PRT"
		replace since1985=1 if iso=="KOR"
		replace since1985=1 if iso=="ESP"
		replace since1985=1 if iso=="USA"
		
		gen generation=1 if year_of_birth>=1910 & year_of_birth<=1924
		replace generation=2 if year_of_birth>1924 & year_of_birth<=1944
		replace generation=3 if year_of_birth>1944 & year_of_birth<=1964
		replace generation=4 if year_of_birth>1964 & year_of_birth<=1980
		replace generation=5 if year_of_birth>1980 & year_of_birth<=1996
		replace generation=6 if year_of_birth>1996 & year_of_birth<=2010
	
		label define generation 1 "Greatest" 2 "Silent" 3 "Boomers" 4 "Gen-X" 5 "Gen-Y" 6 "Gen-Z"
		label values generation generation
	
		egen birthcohort = cut(year_of_birth), at(1910 1915 1920 1925 1930 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 	1985 1990 1995 2000  2005)
		replace birthcohort=. if year_of_birth<1910
	
		gen year2=year*year
		gen age2=age*age
	
		egen decade = cut(year), at(1970 1980 1990 2000 2010 2020)
		
		gen isoyear=iso+string(year)
		encode isoyear, gen(isoyear_num)
	
		bysort isoyear_num: egen ideologymean=mean(ideology_st)
		gen ideology_st_deviation=ideology_st-ideologymean
	
		eststo m1: reg ideology_st_deviation i.gender i.decade  i.isocode if since1970==1, cluster(isoyear_num)
		eststo m2: reg ideology_st_deviation i.gender##i.decade   i.isocode if since1970==1, cluster(isoyear_num)
		eststo m3: reg ideology_st_deviation i.gender i.decade  i.isocode if since1985==1, cluster(isoyear_num)
		eststo m4: reg ideology_st_deviation i.gender##i.decade   i.isocode if since1985==1, cluster(isoyear_num)
		eststo m5: reg ideology_st_deviation i.gender i.decade  i.isocode , cluster(isoyear_num)
		eststo m6: reg ideology_st_deviation i.gender##i.decade   i.isocode , cluster(isoyear_num)
	
		esttab m1 m2 m3 m4 m5 m6 using table_deviations.rtf, b(3) se(3) r2 nogap replace
	

	** taking into account survey and scale effects (Appendix F)
	
	eststo m1: reg ideology_st i.gender i.decade b10.scale b2.dataset_category i.isocode if since1970==1, cluster(isoyear_num)
	eststo m2: reg ideology_st i.gender##i.decade b10.scale b2.dataset_category  i.isocode if since1970==1, cluster(			isoyear_num)
	eststo m3: reg ideology_st i.gender i.decade b10.scale b2.dataset_category i.isocode if since1985==1, cluster(isoyear_num)
	eststo m4: reg ideology_st i.gender##i.decade  b10.scale b2.dataset_category i.isocode if since1985==1, cluster(			isoyear_num)
	eststo m5: reg ideology_st i.gender i.decade b10.scale b2.dataset_category i.isocode , cluster(isoyear_num)
	eststo m6: reg ideology_st i.gender##i.decade b10.scale b2.dataset_category  i.isocode , cluster(isoyear_num)
	
	esttab m1 m2 m3 m4 m5 m6 using table_surveycontrols.rtf, b(3) se(3) r2 nogap replace

	
	** weighted by population size (Appendix G)
	gen key=iso+"_"+string(year)
	merge m:1 key using "left-right-weights.dta"
		
	eststo m1: reg ideology_st i.gender i.decade  i.isocode [pweight=equalweight], cluster(isoyear_num)
	eststo m2: reg ideology_st i.gender##i.decade    i.isocode [pweight=equalweight], cluster(isoyear_num)
	
	eststo m3: reg ideology_st i.gender i.decade  i.isocode [pweight=populationweight], cluster(isoyear_num)
	eststo m4: reg ideology_st i.gender##i.decade   i.isocode [pweight=populationweight], cluster(isoyear_num)

	esttab m1 m2 m3 m4  using table_weights.rtf, b(3) se(3) r2 nogap replace
	
	
	** meaning and relevance of left-right (Appendix H)
	
		* part 1: meaning of left-right positions, analysis of Caughey, O’Grady and Warshaw (2019) dataset
	
		gen biennium=1 if year==1981
		replace biennium=1 if year==1982
		replace biennium=2 if year==1983
		replace biennium=2 if year==1984
		replace biennium=3 if year==1985
		replace biennium=3 if year==1986
		replace biennium=4 if year==1987
		replace biennium=4 if year==1988
		replace biennium=5 if year==1989
		replace biennium=5 if year==1990
		replace biennium=6 if year==1991
		replace biennium=6 if year==1992
		replace biennium=7 if year==1993
		replace biennium=7 if year==1994
		replace biennium=8 if year==1995
		replace biennium=8 if year==1996
		replace biennium=9 if year==1997
		replace biennium=9 if year==1998
		replace biennium=10 if year==1999
		replace biennium=10 if year==2000
		replace biennium=11 if year==2001
		replace biennium=11 if year==2002
		replace biennium=12 if year==2003
		replace biennium=12 if year==2004
		replace biennium=13 if year==2005
		replace biennium=13 if year==2006
		replace biennium=14 if year==2007
		replace biennium=14 if year==2008
		replace biennium=15 if year==2009
		replace biennium=15 if year==2010
		replace biennium=16 if year==2011
		replace biennium=16 if year==2012
		replace biennium=17 if year==2013
		replace biennium=17 if year==2014
		replace biennium=18 if year==2015
		replace biennium=18 if year==2016
	
		drop if biennium==.
	
		gen isobiennium=iso+string(biennium)
		collapse (mean) ideology_st (first) iso year , by(isobiennium)
	
		merge 1:1 isobiennium using "Caughey et al_coded.dta"
	
		encode iso, gen(isonum)
		eststo m1: reg ideology_st econ_abs_post_mean biennium , cluster(isonum)
		eststo m2: reg ideology_st c.econ_abs_post_mean##c.biennium , cluster(isonum)
	
		eststo m3:reg ideology_st econ_rel_post_mean biennium , cluster(isonum)
		eststo m4:reg ideology_st c.econ_rel_post_mean##c.biennium , cluster(isonum)
		
		eststo m5:reg ideology_st soc_post_mean biennium , cluster(isonum)
		eststo m6:reg ideology_st c.soc_post_mean##c.biennium , cluster(isonum)
	
		eststo m7:reg ideology_st immi_post_mean biennium , cluster(isonum)
		eststo m8:reg ideology_st c.immi_post_mean##c.biennium , cluster(isonum)
	
		esttab m1 m2 m3 m4 m5 m6 m7 m8 using table_leftrightmeaning.rtf, b(3) se(3) r2 nogap replace
	
	
		* part 2: relevance of left-right positions, analysis of CSES data

		use "CSES_combined_coded_long.dta", clear 
	
		keep if oecd==1
	
		reg votechoicep pidp dist_party
		keep if e(sample)==1
	
		encode A1004, gen(A1004_num)
		numlabel, add
		tab A1004_num
	
		set more off
		tempname electionanalyses
	
		postfile `electionanalyses' A1004 b_dist_party se_dist_party using electionanalyses.dta , replace

		foreach i of num 1/118  {
		clogit votechoicep pidp dist_party if A1004_num==`i' , group(id)
		post `electionanalyses' (`i') (`=_b[dist_party]') (`=_se[dist_party]') 
		}
		postclose `electionanalyses' 

	
		use "electionanalyses.dta", clear					
	
		label define a1004 1 "AUS_1996" 2 "AUS_2004" 3 "AUS_2007" 4 "AUS_2013" 5 "AUT_2008" 6 "AUT_2013" ///
		7 "AUT_2017" 8 "CAN_1997" 9 "CAN_2004" 10 "CAN_2008" 11 "CAN_2011" 12 "CAN_2015" 13 "CHE_1999" ///
		14 "CHE_2003" 15 "CHE_2007" 16 "CHE_2011" 17 "CHL_2005" 18 "CHL_2009" 19 "CHL_2017" 20 "CZE_1996" ///
		21 "CZE_2002" 22 "CZE_2006" 23 "CZE_2010" 24 "CZE_2013" 25 "DEU_1998" 26 "DEU_2005" 27 "DEU_2009" ///
		28 "DEU_2013" 29 "DEU_2017" 30 "DNK_1998" 31 "DNK_2001" 32 "DNK_2007" 33 "ESP_1996" 34 "ESP_2000" ///
		35 "ESP_2004" 36 "ESP_2008" 37 "EST_2011" 38 "FIN_2003" 39 "FIN_2007" 40 "FIN_2011" 41 "FIN_2015" ///
		42 "FRA_2007" 43 "GBR_1997" 44 "GBR_2005" 45 "GBR_2015" 46 "GRC_2009" 47 "GRC_2012" 48 "GRC_2015" ///
		49 "HUN_1998" 50 "HUN_2002" 51 "HUN_2018" 52 "IRL_2002" 53 "IRL_2007" 54 "IRL_2011" 55 "IRL_2016" ///
		56 "ISL_1999" 57 "ISL_2003" 58 "ISL_2007" 59 "ISL_2009" 60 "ISL_2013" 61 "ISR_1996" 62 "ISR_2003" ///
		63 "ISR_2006" 64 "ISR_2013" 65 "ITA_2006" 66 "ITA_2018" 67 "JPN_2007" 68 "JPN_2013" 69 "KOR_2004" ///
		70 "KOR_2008" 71 "KOR_2012" 72 "KOR_2016" 73 "LTU_2016" 74 "LVA_2010" 75 "LVA_2011" 76 "LVA_2014" ///
		77 "MEX_1997" 78 "MEX_2000" 79 "MEX_2003" 80 "MEX_2006" 81 "MEX_2009" 82 "MEX_2012" 83 "MEX_2015" ///
		84 "NLD_1998" 85 "NLD_2002" 86 "NLD_2006" 87 "NLD_2010" 88 "NOR_1997" 89 "NOR_2001" 90 "NOR_2005" ///
		91 "NOR_2009" 92 "NOR_2013" 93 "NZL_1996" 94 "NZL_2002" 95 "NZL_2008" 96 "NZL_2011" 97 "NZL_2014" ///
		98 "POL_1997" 99 "POL_2001" 100 "POL_2005" 101 "POL_2007" 102 "POL_2011" 103 "PRT_2002" 104 "PRT_2005" ///
		105 "PRT_2009" 106 "PRT_2015" 107 "SVK_2010" 108 "SVK_2016" 109 "SWE_1998" 110 "SWE_2002" 111 "SWE_2006" ///
		112 "SWE_2014" 113 "TUR_2011" 114 "TUR_2015" 115 "USA_2004" 116 "USA_2008" 117 "USA_2012" 118 "USA_2016" ///
		
		label values A1004 a1004 
 	
		serrbar b_dist_party se_dist_party A1004 , scale (1.96)  ytitle("Coefficient of ideological distance") ///
		xtitle("") yline(0) xlabel(1(1)118, valuelabel)	saving(distance.gph, replace)
	
		decode A1004, gen(election) 
		split election, p("_")
		rename election1 country
		encode country, gen(countrynum)
		rename election2 year
		destring year, replace
		
		reg b_dist_party year i.countrynum, cluster(country)




